package breeze.pixel.weather.error_view.model;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.io.File;
import java.text.SimpleDateFormat;

public class FeedBackUtils {

    public static String TAG = FeedBackUtils.class.getSimpleName();

    public static String getTime(){
        @SuppressLint("SimpleDateFormat") SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sd.format(System.currentTimeMillis());
    }

    public static String getAndroidVersion()
    {
        return android.os.Build.VERSION.RELEASE;
    }

    public static String getAppVersion(Context Context)
    {
        String strVersion = null;
        try
        {
            PackageInfo pi;
            pi = Context.getPackageManager().getPackageInfo(Context.getPackageName(), 0);
            if (pi != null)
            {
                strVersion = pi.versionName;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return "";
        }
        return strVersion;
    }

    public static String getAppName(Context Context)
    {
        PackageManager pm = Context.getPackageManager();
        try
        {
            ApplicationInfo info = pm.getApplicationInfo(Context.getPackageName(), 0);
            return pm.getApplicationLabel(info).toString();
        }
        catch (PackageManager.NameNotFoundException e)
        {e.printStackTrace();
            return "";}
    }

    public static String getPackageName(Context Context)
    {
        return Context.getPackageName();
    }

    public static String getPhoneName()
    {
        return android.os.Build.BRAND;
    }

    public static boolean getIsRoot()
    {
        boolean isRoot;
        try
        {
            isRoot = (new File("/system/bin/su").exists())
                || (new File("/system/xbin/su").exists());
        }
        catch (Exception e)
        {
            return false;
        }
        return isRoot;
	}
    
}
